import { defineStore } from 'pinia'
import goodsDetails from '../api/goodsDetails'
import brandDetails from '../api/brandDetails'
import getList from '../api/list'

export const useDetailsStore = defineStore('details', {
  state: () => ({
    goodsData: {},
    brandData: {},
    list: {}
  }),
  actions: {
    async fetchGetgoodsDetails(id) {
      try {
        const res = await goodsDetails(id)
        if (Object.keys(res).length > 0) {
          this.goodsData = res.data
        }
      } catch (error) {
        console.error('获取详情数据失败：', error)
      }
    },
    async fetchGetbrandDetails(id) {
      try {
        const res = await brandDetails(id)
        const listRes = await getList(id)
        if (Object.keys(res).length > 0 && Object.keys(listRes).length > 0) {
          this.brandData = res.data
          this.list = listRes.data
        }
      } catch (error) {
        console.error('获取详情数据失败：', error)
      }
    }
  }
})
